// @ts-nocheck
import {reactive, ref} from "vue";
import {ElMessage} from "element-plus";
import {axios_request} from "@/api/milliaAxios";
import {sleep} from "@/static/Login_Register/register";


export const isResetPassword = ref(false);

export const forgetForm = reactive({
    telephone: "",
    password: "",
    code: "",
})


export const changePassword = async () => {
    const reg = /^1[3-9]\d{9}$/;

    if (!forgetForm.telephone) {
        return ElMessage.warning('请输入手机号码')
    }


    if (reg.test(forgetForm.telephone)) {
        //发送短信的api接口
        const res = await axios_request('/api/user/forgetpwd/', JSON.stringify(forgetForm), 'post');
        console.log("POST请求返回的数据：" + res);
        console.log(res);

        if (res.status == 200) {
            ElMessage.success(res.data.msg)
            await sleep(1000);
            window.location.reload();
        }else {
            ElMessage.warning(res.data.msg)
        }
    } else {
        ElMessage.warning('请输入正确的手机号码')
    }
}